package com.hyacinth.server.bean;

import javafx.scene.Parent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 默认容器实现
 * @author zhangfb
 * @version 1.0.0.1
 * @since JDK 1.8
 */
public class AuroraDefaultIoC implements AuroraBeanFactory {

    private static final Logger LOGGER = LoggerFactory.getLogger(AuroraDefaultIoC.class);

    private final Map<String, Object> beanMap = new ConcurrentHashMap<>(256);

    @Override
    public void register(Object object) {
        register(object.toString().split(" ")[1], object);
    }

    @Override
    public void register(String beanName, Object object) {
        beanMap.put(beanName, object);
    }

    @Override
    public Object getBean(String name) throws Exception {
        return beanMap.get(name);
    }

    @Override
    public void releaseBean() {
        beanMap.clear();
        LOGGER.info("release all bean success.");
    }
}
